<?php
/* Author: tbloc@cantho.gov.vn */
/* Created Date : 17-07-2014 10:10:51 */
class M_Hoa_don{  
//Properties
private $HD_ID;
private $NV_ID;
private $HD_NGAYLAP;
private $HD_TRANGTHAI;
//properties set get 
public function setHD_ID($HD_ID) 
{
	$this->HD_ID = $HD_ID;
}
public function getHD_ID()
{
	return $this->HD_ID;
}	        
public function setNV_ID($NV_ID) 
{
	$this->NV_ID = $NV_ID;
}
public function getNV_ID()
{
	return $this->NV_ID;
}	        
public function setHD_NGAYLAP($HD_NGAYLAP) 
{
	$this->HD_NGAYLAP = $HD_NGAYLAP;
}
public function getHD_NGAYLAP()
{
	return $this->HD_NGAYLAP;
}	        
public function setHD_TRANGTHAI($HD_TRANGTHAI) 
{
	$this->HD_TRANGTHAI = $HD_TRANGTHAI;
}
public function getHD_TRANGTHAI()
{
	return $this->HD_TRANGTHAI;
}	        
//crud methods
public function insert($db = null) {
	if ($db != null){
	$sql = "INSERT INTO `hoa_don`(                        
			`HD_ID`, 
				`NV_ID`, 
				`HD_NGAYLAP`, 
				`HD_TRANGTHAI` 
		)
	VALUES(
    		:HD_ID, 
	    		:NV_ID, 
	    		:HD_NGAYLAP, 
	    		:HD_TRANGTHAI 
	    );";
	$parameters = array(
			":HD_ID", 
				":NV_ID", 
				":HD_NGAYLAP", 
				":HD_TRANGTHAI" 
		);
    $values = array(  
            	$this->getHD_ID(), 
	            	$this->getNV_ID(), 
	            	$this->getHD_NGAYLAP(), 
	            	$this->getHD_TRANGTHAI()
	    );
    $types = array(
   
                                    PDO::PARAM_INT,
                                                       PDO::PARAM_INT,
                                                       PDO::PARAM_STR,
                                                        PDO::PARAM_INT
                       );
	$lastInsertID = $db->executeNonQuery($sql, $parameters, $values, $types, true);
	$this->setHD_ID($lastInsertID);
    }
}
	
	public function delete($db = null) {
	    if ($db != null) {
	        $sql = "update `hoa_don`
	                set `is_active`=0
	                where `HD_ID` = :HD_ID;";
	        $parameters = array(":HD_ID");
	        $values = array($this->getHD_ID());
	        $types = array(PDO::PARAM_INT);//Kiem tra lai kieu du lieu nhe
	        $result = $db->executeNonQuery($sql, $parameters, $values, $types);
	        return $result;
	    }
	}
	
	public function update($db = null) {
	        if ($db != null) {
	            $sql = "UPDATE `hoa_don` SET 
			`HD_ID`=:HD_ID,
				`NV_ID`=:NV_ID,
				`HD_NGAYLAP`=:HD_NGAYLAP,
				`HD_TRANGTHAI`=:HD_TRANGTHAI
			WHERE `HD_ID` = :HD_ID;";
	            $parameters = array(
	        	":HD_ID",
		        	":NV_ID",
		        	":HD_NGAYLAP",
		        	":HD_TRANGTHAI"
		        );	
	$values = array(  
	        	$this->getHD_ID(),
        	        	$this->getNV_ID(),
        	        	$this->getHD_NGAYLAP(),
        	                $this->getHD_TRANGTHAI()      
        	);
    $types = array(
                                    PDO::PARAM_INT,
                                                       PDO::PARAM_INT,
                                                       PDO::PARAM_STR,
                                                       PDO::PARAM_INT
                       );
	$result = $db->executeNonQuery($sql, $parameters, $values, $types);
	return $result;
	        }
	 }
	 
	public function getByID($db = null) {
	if ($db != null) {
	$sql = "SELECT
			`HD_ID`,
				`NV_ID`,
				`HD_NGAYLAP`,
				`HD_TRANGTHAI`
			FROM `hoa_don` WHERE `HD_ID` = :HD_ID and `is_active`=1;";
	$parameters = array(":HD_ID");
	$values = array($this->getHD_ID());
	$types = array(PDO::PARAM_INT);//kiem tra lai kieu du lieu nhe
	$rows = $db->executeQuery($sql, $parameters, $values, $types);
	if ($rows != null) {
	$row = $rows->fetch();
		$this->setHD_ID($row->HD_ID);
		$this->setNV_ID($row->NV_ID);
		$this->setHD_NGAYLAP($row->HD_NGAYLAP);
		$this->setHD_TRANGTHAI($row->HD_TRANGTHAI);
	}
	return $this;
		}
	}
	
	public function getList($db = null) {
	if ($db != null) {
    $sql = "SELECT
			`HD_ID`,
				`NV_ID`,
				`HD_NGAYLAP`,
				`HD_TRANGTHAI`
			FROM `hoa_don` WHERE `is_active`=1;";
    $rows = $db->executeQuery($sql);
    $objects = array();
    if ($rows != null) {
    while ($row = $rows->fetch()) {
    $obj = new hoa_don();
    	 $obj->setHD_ID($row->HD_ID);
		 $obj->setNV_ID($row->NV_ID);
		 $obj->setHD_NGAYLAP($row->HD_NGAYLAP);
		 $obj->setHD_TRANGTHAI($row->HD_TRANGTHAI);
		$objects[] = $obj;
    }
    return $objects;
    }
        }
    }
}
?>

